/*     */ package net.sourceforge.appgen.job;
/*     */ 
/*     */ import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import net.sourceforge.appgen.editor.MappingDataEditor;
import net.sourceforge.appgen.generator.AdminContextInterceptorGenerator;
import net.sourceforge.appgen.generator.AdminLocaleInterceptorGenerator;
import net.sourceforge.appgen.generator.BaseCriteriaFileGenerator;
import net.sourceforge.appgen.generator.BindingInitializerFileGenerator;
import net.sourceforge.appgen.generator.ConstantsGenerator;
import net.sourceforge.appgen.generator.ControllerFileGenerator;
import net.sourceforge.appgen.generator.CriteriaFileGenerator;
import net.sourceforge.appgen.generator.DaoInterfaceFileGenerator;
import net.sourceforge.appgen.generator.DateTypeEditorFileGenerator;
import net.sourceforge.appgen.generator.DefaultPagingFileGenerator;
import net.sourceforge.appgen.generator.DetailPageFileGenerator;
import net.sourceforge.appgen.generator.DialectGenerator;
import net.sourceforge.appgen.generator.EditPageFileGenerator;
import net.sourceforge.appgen.generator.EntityFileGenerator;
import net.sourceforge.appgen.generator.FileGenerator;
import net.sourceforge.appgen.generator.HttpSessionProviderGenerator;
import net.sourceforge.appgen.generator.IndexFileGenerator;
import net.sourceforge.appgen.generator.JdbcDriverFileGenerator;
import net.sourceforge.appgen.generator.JdbcPropertiesFileGenerator;
import net.sourceforge.appgen.generator.ListPageFileGenerator;
import net.sourceforge.appgen.generator.LogbackFileGenerator;
import net.sourceforge.appgen.generator.MessageFileGenerator;
import net.sourceforge.appgen.generator.MessageKoPropertiesFileGenerator;
import net.sourceforge.appgen.generator.MessagePropertiesFileGenerator;
import net.sourceforge.appgen.generator.MismatchParameterFileGenerator;
import net.sourceforge.appgen.generator.MySQL5DialectGenerator;
import net.sourceforge.appgen.generator.OrcaleDialectGenerator;
import net.sourceforge.appgen.generator.PaginationInterceptorGenerator;
import net.sourceforge.appgen.generator.PagingFileGenerator;
import net.sourceforge.appgen.generator.RequiredParameterFileGenerator;
import net.sourceforge.appgen.generator.ResourcePropertiesFileGenerator;
import net.sourceforge.appgen.generator.RichFreeMarkerViewGenerator;
import net.sourceforge.appgen.generator.RichFreeMarkerViewResolverGenerator;
import net.sourceforge.appgen.generator.ServiceClassFileGenerator;
import net.sourceforge.appgen.generator.ServiceInterfaceFileGenerator;
import net.sourceforge.appgen.generator.ServletXmlFileGenerator;
import net.sourceforge.appgen.generator.SessionProviderGenerator;
import net.sourceforge.appgen.generator.SqlMapConfigFileGenerator;
import net.sourceforge.appgen.generator.SqlMapFileGenerator;
import net.sourceforge.appgen.generator.UploadSaveDirectoryGenerator;
import net.sourceforge.appgen.generator.ValidatorFileGenerator;
import net.sourceforge.appgen.generator.ValidatorShowGenerator;
import net.sourceforge.appgen.generator.WebXmlFileGenerator;
import net.sourceforge.appgen.generator.WritePageFileGenerator;
import net.sourceforge.appgen.generator.bindExceptionFileGenerator;
import net.sourceforge.appgen.model.ConnectionInformation;
import net.sourceforge.appgen.model.Entity;
import net.sourceforge.appgen.model.GenerationInformation;
import net.sourceforge.appgen.model.MappingData;

import org.apache.commons.lang.Validate;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.actions.RefreshAction;
import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.console.MessageConsoleStream;
import org.eclipse.ui.part.EditorPart;
/*     */ 
/*     */ public class GenerateFileJob extends Job
/*     */ {
/*     */   private EditorPart editor;
/*     */   private MappingData mappingData;
/*     */ 
/*     */   public GenerateFileJob(MappingData mappingData, EditorPart editor, String text)
/*     */   {
/*  95 */     super(text);
/*     */ 
/*  97 */     this.mappingData = mappingData;
/*  98 */     this.editor = editor;
/*     */   }
/*     */ 
/*     */   protected IStatus run(final IProgressMonitor monitor)
/*     */   {
/* 103 */     Display.getDefault().asyncExec(new Runnable() {
/*     */       public void run() {
/* 105 */         GenerateFileJob.this.runInternal(monitor);
/*     */       }
/*     */     });
/* 109 */     return Status.OK_STATUS;
/*     */   }
/*     */ 
/*     */   private void runInternal(IProgressMonitor monitor) {
/*     */     try {
/* 114 */       List<FileGenerator> fileGeneratorList = new ArrayList();
/*     */ 
/* 116 */       ConnectionInformation connectionInformation = this.mappingData.getConnectionInformation();
/* 117 */       GenerationInformation generationInformation = this.mappingData.getGenerationInformation();
/* 118 */       List<Entity> entityList = this.mappingData.getEntityList();
/*     */ 
/* 121 */       //fileGeneratorList.add(new WebXmlFileGenerator(generationInformation));
/* 122 */       //fileGeneratorList.add(new ServletXmlFileGenerator(generationInformation, entityList));
/* 123 */       fileGeneratorList.add(new SqlMapConfigFileGenerator(generationInformation, entityList));
/* 125 */       //fileGeneratorList.add(new LogbackFileGenerator(generationInformation));
/* 126 */       //fileGeneratorList.add(new MessagePropertiesFileGenerator(generationInformation));
				//fileGeneratorList.add(new MessageFileGenerator(generationInformation));
/* 127 */       //fileGeneratorList.add(new MessageKoPropertiesFileGenerator(generationInformation));
/*     */ 
/* 129 */       //fileGeneratorList.add(new JdbcPropertiesFileGenerator(generationInformation, connectionInformation));
/* 130 */       //fileGeneratorList.add(new ResourcePropertiesFileGenerator(generationInformation));
/*     */ 
/* 132 */       //fileGeneratorList.add(new JdbcDriverFileGenerator(generationInformation, connectionInformation));
/*     */ 
/* 134 */       //fileGeneratorList.add(new BaseCriteriaFileGenerator(generationInformation));
				//fileGeneratorList.add(new AdminContextInterceptorGenerator(generationInformation));
				
				//fileGeneratorList.add(new BindingInitializerFileGenerator(generationInformation));
				//fileGeneratorList.add(new DateTypeEditorFileGenerator(generationInformation));
				
				//fileGeneratorList.add(new AdminLocaleInterceptorGenerator(generationInformation));
				//fileGeneratorList.add(new HttpSessionProviderGenerator(generationInformation));
				//fileGeneratorList.add(new SessionProviderGenerator(generationInformation));
				//fileGeneratorList.add(new RichFreeMarkerViewGenerator(generationInformation));
				//fileGeneratorList.add(new RichFreeMarkerViewResolverGenerator(generationInformation));
				//fileGeneratorList.add(new ConstantsGenerator(generationInformation));
				
				
/* 136 */       //fileGeneratorList.add(new PagingFileGenerator(generationInformation));
/*     */ 		
				//fileGeneratorList.add(new PaginationInterceptorGenerator(generationInformation));
				//fileGeneratorList.add(new DialectGenerator(generationInformation));
				//fileGeneratorList.add(new MySQL5DialectGenerator(generationInformation));
				//fileGeneratorList.add(new OrcaleDialectGenerator(generationInformation));
				
/* 138 */       //fileGeneratorList.add(new UploadSaveDirectoryGenerator(generationInformation));
/*     */ 		
//fileGeneratorList.add(new RequiredParameterFileGenerator(generationInformation));
/*     */		//fileGeneratorList.add(new bindExceptionFileGenerator(generationInformation));
//fileGeneratorList.add(new MismatchParameterFileGenerator(generationInformation));
/* 150 */       fileGeneratorList.add(new EntityFileGenerator(generationInformation));
/* 151 */       //fileGeneratorList.add(new CriteriaFileGenerator(generationInformation));
/* 152 */       //fileGeneratorList.add(new ValidatorShowGenerator(generationInformation));
/* 153 */       fileGeneratorList.add(new DaoInterfaceFileGenerator(generationInformation));
/* 155 */       fileGeneratorList.add(new SqlMapFileGenerator(generationInformation));
/* 156 */       fileGeneratorList.add(new ServiceInterfaceFileGenerator(generationInformation));
/* 157 */       fileGeneratorList.add(new ServiceClassFileGenerator(generationInformation));
/* 158 */       fileGeneratorList.add(new ControllerFileGenerator(generationInformation));
/*     */ 
/* 165 */       fileGeneratorList.add(new IndexFileGenerator(generationInformation, entityList));
/* 166 */       fileGeneratorList.add(new ListPageFileGenerator(generationInformation));
/* 167 */       fileGeneratorList.add(new DetailPageFileGenerator(generationInformation));
/* 168 */       fileGeneratorList.add(new WritePageFileGenerator(generationInformation));
/* 169 */       fileGeneratorList.add(new EditPageFileGenerator(generationInformation));
/*     */ 
/* 173 */       monitor.beginTask("Generate soure files", (entityList != null) && (entityList.size() > 0) ? entityList.size() * fileGeneratorList.size() : 0);
/*     */ 
/* 175 */       if ((entityList != null) && (entityList.size() > 0)) {
/* 176 */         boolean overwriteYesToAll = false;
/* 177 */         boolean overwriteNoToAll = false;
/*     */ 
/* 179 */         List generatedFileList = new ArrayList();
/*     */ 
/* 182 */         for (FileGenerator fileGenerator : fileGeneratorList) {
/* 183 */           fileGenerator.generateDirectory();
/*     */ 
/* 185 */           for (Entity entity : entityList) {
/* 186 */             monitor.subTask(fileGenerator.getFile(entity).getPath());
/*     */ 
/* 188 */             if (entity.isCreate()) {
/*     */               try {
/* 190 */                 if (fileGenerator.existFile(entity)) {
/* 191 */                   if (overwriteNoToAll)
/*     */                   {
/*     */                     continue;
/*     */                   }
/* 195 */                   if (!overwriteYesToAll) {
/* 196 */                     boolean overwrite = false;
/*     */ 
/* 198 */                     MessageDialog overwriteDialog = new MessageDialog(
/* 199 */                       this.editor.getSite().getShell(), 
/* 200 */                       "Question", 
/* 201 */                       null, 
/* 202 */                       "The file '" + fileGenerator.getFile(entity) + "' already exists. Do you want to replace the existing file?", 
/* 203 */                       4, 
/* 204 */                       new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.NO_TO_ALL_LABEL }, 
/* 205 */                       1);
/*     */ 
/* 207 */                     int value = overwriteDialog.open();
/*     */ 
/* 209 */                     switch (value) {
/*     */                     case 0:
/* 211 */                       overwrite = true;
/* 212 */                       break;
/*     */                     case 1:
/* 214 */                       overwrite = false;
/* 215 */                       break;
/*     */                     case 2:
/* 217 */                       overwrite = true;
/* 218 */                       overwriteYesToAll = true;
/* 219 */                       break;
/*     */                     case 3:
/* 221 */                       overwrite = false;
/* 222 */                       overwriteNoToAll = true;
/* 223 */                       break;
/*     */                     default:
/* 225 */                       overwriteNoToAll = true;
/*     */                     }
/*     */ 
/* 229 */                     if (!overwrite)
/*     */                     {
/*     */                       continue;
/*     */                     }
/*     */                   }
/*     */                 }
/* 235 */                 entity.setPackageName(generationInformation.getPackageName());
/*     */ 
/* 237 */                 File file = fileGenerator.generate(entity);
/*     */ 
/* 239 */                 if (file != null)
/* 240 */                   generatedFileList.add(file);
/*     */               }
/*     */               catch (Exception e) {
/* 243 */                 MessageDialog.openError(this.editor.getSite().getShell(), "Error - generate", e.getMessage());
/*     */               }
/*     */             }
/*     */             else {
/* 247 */               monitor.worked(1);
/*     */             }
/*     */           }
/*     */         }
/* 251 */         printGeneratedFileList(generatedFileList);
/*     */       }
/*     */ 
/* 254 */       RefreshAction refreshAction = new RefreshAction(this.editor.getEditorSite());
/* 255 */       refreshAction.refreshAll();
/*     */ 
/* 257 */       monitor.done();
/*     */     } catch (Exception e) {
/* 259 */       MessageDialog.openError(this.editor.getSite().getShell(), "Generate file error", e.getMessage());
/*     */     }
/*     */   }
/*     */ 
/*     */   private void printGeneratedFileList(List<File> generatedFileList)
/*     */   {
/* 265 */     if (generatedFileList == null) {
/* 266 */       return;
/*     */     }
/*     */ 
/* 269 */     Collections.sort(generatedFileList);
/*     */ 
/* 271 */     MappingDataEditor mappingDataEditor = (MappingDataEditor)this.editor;
/* 272 */     MessageConsole console = mappingDataEditor.getConsole();
/* 273 */     MessageConsoleStream out = console.newMessageStream();
/* 274 */     out.setActivateOnWrite(true);
/*     */ 
/* 276 */     out.println("---- AppGen: Generated information ----------------------------------------------------------------");
/* 277 */     out.println(generatedFileList.size() + " files generated.");
/* 278 */     out.println("---- file list ------------------------------------------------------------------------------------");
/*     */ 
/* 280 */     for (File file : generatedFileList) {
/* 281 */       out.println(file.toString());
/*     */     }
/*     */ 
/* 284 */     out.println("---------------------------------------------------------------------------------------------------");
/*     */   }
/*     */ }

/* Location:           C:\Users\lzl6066\Downloads\net.sourceforge.appgen_1.2.0\plugins\net.sourceforge.appgen_1.2.0.201002031718\
 * Qualified Name:     net.sourceforge.appgen.job.GenerateFileJob
 * JD-Core Version:    0.6.0
 */